﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace MoskieBlog.Helpers
{
    public static class HtmlExtensions
    {
        public static MvcHtmlString ActionMenuItem(this HtmlHelper htmlHelper, String linkText, String actionName, String controllerName)
        {
            var tag = new TagBuilder("li");

            if (htmlHelper.ViewContext.RequestContext.IsCurrentRoute(null, controllerName, actionName))
            {
                tag.AddCssClass("active");
            }

            tag.InnerHtml = htmlHelper.ActionLink(linkText, actionName, controllerName).ToString();

            return MvcHtmlString.Create(tag.ToString());
        }

        public static MvcHtmlString ActionMenuItem(this HtmlHelper htmlHelper, String linkText, String controllerName)
        {
            var tag = new TagBuilder("li");

            if (htmlHelper.ViewContext.RequestContext.IsCurrentRoute(null, controllerName))
            {
                tag.AddCssClass("active");
            }

            tag.InnerHtml = htmlHelper.ActionLink(linkText, "Index", controllerName).ToString();

            return MvcHtmlString.Create(tag.ToString());
        }

        public static MvcHtmlString ActionMenuItem(this HtmlHelper htmlHelper, String controllerName)
        {
            var tag = new TagBuilder("li");

            if (htmlHelper.ViewContext.RequestContext.IsCurrentRoute(null, controllerName))
            {
                tag.AddCssClass("active");
            }

            tag.InnerHtml = htmlHelper.ActionLink(controllerName, "Index", controllerName).ToString();

            return MvcHtmlString.Create(tag.ToString());
        }
    }
}